Skip to content

feat(ci): improve container build process v2#9317

Merged
eliotlim merged 13 commits intodevelopfrom
feat/ci/improve-container-build-process-v2
Apr 22, 2026
Merged

feat(ci): improve container build process v2#9317
eliotlim merged 13 commits intodevelopfrom
feat/ci/improve-container-build-process-v2

Conversation

@eliotlim
Copy link
Copy Markdown
Contributor

@eliotlim eliotlim commented Apr 16, 2026

Problem

The CI pipeline is inefficient, because containers are built several times over and over for each environment.

Closes FRM-2351.

Related to #9276, #9286.

Solution

Breaking Changes

  • No - this PR is backwards compatible

Improvements:

  • use GitHub Container Registry (GHCR) to store pre-built base and release images
  • build images once on the release branch to reduce deployment time
  • refine hardcoded VITE_APP_* constants
    • only constants are built into the Vite output: APP_VERSION, DD_RUM_APP_ID, DD_RUM_CLIENT_TOKEN
    • moved to backend-loaded runtimeEnv / clientEnv: appUrl, apiBaseUrl: '/api/v3', gaTrackingId, formsgSdkMode, ddRumEnv, ddSampleRate

Bug Fixes:

  • Replace npx @datadog/datadog-ci with the binary version for sourcemap upload

Tests

TC1: Deployment and Versioning works correctly

  • Deployments to STG and PRD should work normally.
  • The application version should be correctly tagged to logs and metrics in DataDog.

TC2: Admins must be able to download results on the results page

  • Visit an existing form's results page
  • Click Download, select all options, and Download.
  • All the files and CSVs should be downloaded correctly.

Deploy Notes

@eliotlim eliotlim requested a review from a team as a code owner April 16, 2026 12:48
Copilot AI review requested due to automatic review settings April 16, 2026 12:48
@linear
Copy link
Copy Markdown

linear Bot commented Apr 16, 2026

@eliotlim eliotlim self-assigned this Apr 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the container build/deploy pipeline by introducing pre-built base images and a release image flow, while moving several frontend configuration values from build-time Vite envs to runtime-injected window.__ENV__ served by the backend.

Changes:

  • Add runtime frontend env injection (window.__ENV__) from the backend and update the frontend to consume it via a centralized env helper.
  • Introduce Dockerfile.base (build-base + runtime-base) and update Dockerfile.production to build from those base images.
  • Update GitHub Actions workflows to (a) ensure base images exist, (b) optionally reuse pre-built release images, and (c) move Datadog sourcemap upload out of the Docker build.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/shared/types/core.ts Adds FrontendRuntimeEnv type shared between backend injection and frontend consumption.
apps/frontend/vite.config.ts Adds a Vite plugin to replace @VITE_APP_* placeholders at build time.
apps/frontend/src/utils/formSdk.ts Switches FormSG SDK mode selection to use centralized env.
apps/frontend/src/services/ApiService.ts Switches API base URL to use centralized env.
apps/frontend/src/index.tsx Switches GA tracking ID lookup to use centralized env.
apps/frontend/src/growthbook.ts Switches app URL usage to use centralized env.
apps/frontend/src/features/public-form/utils/axiosDebugFlow.tsx Uses centralized env for app URL and avoids variable shadowing.
apps/frontend/src/env.ts New centralized runtime/build-time env resolver using window.__ENV__ with Vite fallbacks.
apps/frontend/src/app/AppHelmet.tsx Uses centralized env for GA tracking ID.
apps/frontend/src/app/App.tsx Updates Datadog Logs env selection to prefer runtime window.__ENV__.
apps/frontend/index.html Adds <!-- __ENV_INJECTION__ --> placeholder for backend injection.
apps/frontend/datadog-chunk.ts Moves Datadog RUM env/sample-rate/appUrl to runtime window.__ENV__ while keeping appId/token/version build-time.
apps/backend/src/app/modules/frontend/frontend.service.ts Generates runtime env script + CSP hash for inline injection.
apps/backend/src/app/modules/frontend/frontend.controller.ts Injects the runtime env script into index.html before serving.
apps/backend/src/app/loaders/express/constants.ts Adds CSP allowlist entry for the injected env inline script hash.
Dockerfile.production Builds from pre-built base images and passes required Vite build-time vars via build args.
Dockerfile.base New build-base/runtime-base images for caching dependencies and standardizing runtime deps/user.
.github/workflows/deploy-ecs.yml Ensures base images, optionally reuses release images, builds/pushes to ECR, uploads sourcemaps post-build.
.github/workflows/build-release-image.yml New workflow to build/push a versioned “release-*” image to GHCR on tag.
.github/workflows/build-base-images.yml New reusable workflow to build/push build-base and runtime-base images keyed by dependency hash.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/deploy-ecs.yml
Comment thread apps/frontend/datadog-chunk.ts Outdated
Comment thread apps/frontend/src/env.ts
Comment thread apps/frontend/src/env.ts Outdated
Comment thread apps/backend/src/app/modules/frontend/frontend.service.ts Outdated
Comment thread apps/frontend/datadog-chunk.ts Outdated
Comment thread .github/workflows/deploy-ecs.yml
@kevin9foong
Copy link
Copy Markdown
Contributor

There are a couple of copilot review comments that seem to make sense

shall we verify them before merging?

Copy link
Copy Markdown
Contributor Author

yup will do! working on it.

@eliotlim eliotlim force-pushed the feat/ci/improve-container-build-process-v2 branch from 9d04344 to 194e69c Compare April 21, 2026 06:19
@eliotlim eliotlim force-pushed the feat/ci/improve-container-build-process-v2 branch from 194e69c to 8ee1c1e Compare April 22, 2026 04:32
@eliotlim
Copy link
Copy Markdown
Contributor Author

Tested all TCs on staging!

@eliotlim eliotlim merged commit 65fd6b7 into develop Apr 22, 2026
38 checks passed
@eliotlim eliotlim deleted the feat/ci/improve-container-build-process-v2 branch April 22, 2026 05:56
eliotlim added a commit that referenced this pull request Apr 22, 2026
* feat(ci): improve container build process v2 (#9317)

* feat(ci): extract base images

# Conflicts:
#	Dockerfile.production

* feat(frontend,backend,ci): streamline frontend and backend build

* fix(frontend,backend): env script csp header hash computation

* fix(ci): cache built image locally for asset upload step

* fix(ci): use datadog-ci binaries instead of npx

* fix(ci): pin datadog-ci version to v5.11.0

* feat(ci): update runtime-base image packages

* fix(ci): use apk no-cache for upgrades

* fix(ci): pin action versions

* fix(ci): remove extra Dockerfile build commands

* chore: apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix(frontend): address code review comments 2

* fix(frontend): env-free reconstruction of payment download url

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix(frontend): use formsgSdkMode in decryption worker (#9329)

* chore: bump version to 7.12.0

---------

Co-authored-by: Kevin Foong <55353265+kevin9foong@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants